package com.google.samples.apps.paging

import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
import com.google.samples.apps.paging.data.GoodsDataSource
import com.google.samples.apps.paging.data.GoodsDataSourceFactory
import com.google.samples.apps.paging.data.bean.GoodsBean

/**
 * Created by Administrator on 2021/7/12 0012.
 * Describe:
 */
class GoodsViewModel: ViewModel() {
    var goodsPagedList:LiveData<PagedList<GoodsBean>>

    init {
        val config = PagedList.Config.Builder()
            .setEnablePlaceholders(true)
            .setPageSize(GoodsDataSource.SIZE_PAGE)
            .setPrefetchDistance(3)
            .setInitialLoadSizeHint(GoodsDataSource.SIZE_PAGE * 4)
            .setMaxSize(65536 * GoodsDataSource.SIZE_PAGE)
            .build()

        goodsPagedList = LivePagedListBuilder(GoodsDataSourceFactory(), config)
            .build()

    }

}